<!doctype html>
<html class="no-js">

<head>
    <title>幼儿园</title>
    <#include "/boya/template/meta.html" />
</head>

<body>
    <#import "/boya/template/marc.html" as mc />
    <@mc.content>
        <div id="app" class="page">
            <div class="title">库存 / 使用日志 /</div>
            <table class="am-table table">
                <thead>
                    <tr>
                        <th>使用日期</th>
                        <th>使用食材</th>
                        <th>使用数量</th>
                        <th>操作</th>
                    </tr>
                </thead>
                <tbody>
                    <tr v-for="(item, index) in list">
                        <td class="am-text-middle">{{ item.attrs.date }}</td>
                        <td class="am-text-middle">{{ item.attrs.title }}</td>
                        <td class="am-text-middle">{{ item.attrs.content }}</td>
                        <td class="am-text-middle">
                            <button class="am-btn am-btn-danger am-btn-xs" @click="del(item.attrs.id)"><i class="am-icon-trash"></i>&nbsp;删除</button>
                        </td>
                    </tr>
                </tbody>
            </table>
            <#include "/boya/template/page.html" />
        </div>
    </@mc.content>
    <script type="text/javascript">
    var app = new Vue({
        el: '#app',
        data() {
            return {
                list: []
            }
        },
        mounted: function() {
            var jsonStr = '${list!}';
            if (jsonStr != '') {
                this.list = ${list!}
            }
        },
        methods: {
            del(id) {
                var self = this;
                confirm("确认删除？", function() {
                    var param = Qs.stringify({
                        id: id
                    });
                    axios({
                        url: '/boya/delLog',
                        method: 'post',
                        data: param,
                        headers: {
                            'Content-Type': 'application/x-www-form-urlencoded'
                        }
                    })
                    .then(function(response) {
                        if (response.data.status == 200) {
                            // msg("删除成功");
                            window.location.reload();
                        } else {
                            msg("删除失败");
                            console.log(response.data);
                        }
                    })
                    .catch(function(error) {
                        msg("删除失败");
                        console.log(error);
                    });
                })
            },
            onPageChange(val) {
                goPage(val);
            }
        }
    })
    </script>
    <style type="text/css">
    .page {
        padding: 15px;
    }

    .title {
        margin-bottom: 10px;
        font-size: 1.2em;
    }
    </style>
</body>

</html>